/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.sales.impl;

import dao.sales.SalesDao;
import java.util.List;
import java.util.Map;
import model.sales.SalesMst;
import net.sf.jasperreports.engine.JasperPrint;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.sales.SalesService;
import utility.NameValueList;
import utility.StringUtils;

/**
 *
 * @author Lalugina
 */
@Service("salesService")
@Transactional(readOnly=true)
public class SalesServiceImpl implements SalesService{
    
    private static final Logger log = Logger.getLogger(SalesServiceImpl.class);
      
    private String mainQuery = "select distinct sales from SalesMst sales "+
            "left join fetch sales.member member "+
            "left join fetch mst.salesPayment salesPayment "+
            "left join fetch mst.salesDetails salesDetails "+
            "left join fetch salesDetails.item item ";
                
    @Autowired private SalesDao dao;

    @Override
    public boolean save(SalesMst data) {
        return dao.saveData(data);
    }

    @Override
    public boolean delete(SalesMst data) {
         return dao.saveData(data);
    }

    @Override
    public SalesMst get(long id) {
        String q = mainQuery + " where sales.id = "+id;
        return dao.getByCustomQuery(q);
    }

    @Override
    public SalesMst get(String transNum) {
        String q = mainQuery + " where sales.transNum = "+StringUtils.fmtSQLString(transNum);
        return dao.getByCustomQuery(q);
    }

    @Override
    public List<SalesMst> getAll(int start, int num, Map<NameValueList, Object> params) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public JasperPrint printData(long autoId, long id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String printStruk(long id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
